package com.zpl.entity;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

/**
 * @author wangyuxin
 * @date 2020/9/28
 */
@JsonDeserialize(using = BaseEnumDeserializer.class)
@JsonSerialize(using = BaseEnumSerializer.class)
public interface BaseEnum {
    /**
     * @description：必须在子类的重写方法返回具体的枚举name  ，例如return this.name()<br/>
     */
    Integer getCode();
    String getDisplayName();
    String getName();

    /**
     * 根据枚举名称获取枚举
     * @param name
     * @param clazz
     * @param <E>
     * @return
     */
    static <E extends Enum<E>> BaseEnum valueOf(String name, Class<E> clazz) {
        BaseEnum enumm = (BaseEnum) Enum.valueOf(clazz, name);
        return enumm;
    }
}
